﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace POS
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static Menu menu = new Menu();
        public MainWindow()
        {
            InitializeComponent();
            InitializeMenu();
            menu.Render();
        }

       
        //gets the size of the food!
        private FoodOptions.Size GetSizeOfFood(string sizeAsString)
        {
            FoodOptions.Size size = (FoodOptions.Size)Enum.Parse(typeof(FoodOptions.Size), sizeAsString);
            return size;
        }


        //Creates a menu and adds food to it!
        //NOTE: Not tested, not sure it works!
        private void InitializeMenu()
        {
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            DirectoryInfo directoryInfo = new DirectoryInfo("Food");
            FileInfo[] files = directoryInfo.GetFiles();

           // Menu menu = new Menu();

            foreach (var file in files)
            {
                string fileName = file.Name;
                int dotIndex = 0;
                for (; dotIndex < fileName.Length; dotIndex++)
                {
                    if (fileName[dotIndex] == '.')
                    {
                        break;
                    }
                }

                FoodOptions.Type foodType = (FoodOptions.Type)Enum.Parse(typeof(FoodOptions.Type), fileName.Substring(0,dotIndex));
                StreamReader reader = new StreamReader(file.FullName);
                string line = reader.ReadLine();
                while (line != null)
                {
                    string[] components = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    FoodOptions.Size size = GetSizeOfFood(components[3]);
                    components[0] = components[0].Replace('-', ' ');
                    menu.Foods.Add(new Food(components[0], double.Parse(components[1]), double.Parse(components[2]), size, foodType));
                    line = reader.ReadLine();
                }
                reader.Close();
            }

        }

        private void ButtonSaladsMenu(object sender, RoutedEventArgs e)
        {
            Salads buttonSaladsMenu = new Salads();
            buttonSaladsMenu.Show();
            this.Close();
        }

        private void ButtonHotDrinksMenu(object sender, RoutedEventArgs e)
        {
            HotDrinks buttonHotDrinksMenu = new HotDrinks();
            buttonHotDrinksMenu.Show();
            this.Close();
        }

        private void ButtonNonAlcoholicDrinksMenu(object sender, RoutedEventArgs e)
        {

            NonAlcoholicDrinks buttonNonAlcoholicMenu = new NonAlcoholicDrinks();
            buttonNonAlcoholicMenu.Show();
            this.Close();
        }

        private void ButtonAlcoholicDrinksMenu(object sender, RoutedEventArgs e)
        {
            AlcoholicDrinks buttonAlcoholicMenu = new AlcoholicDrinks();
            buttonAlcoholicMenu.Show();
            this.Close();
        }

        private void ButtonDessertsMenu(object sender, RoutedEventArgs e)
        {
            Desserts buttonDessertsMenu = new Desserts();
            buttonDessertsMenu.Show();
            this.Close();
        }

        private void ButtonMealsMenu(object sender, RoutedEventArgs e)
        {
            Meals buttonMealsMenu = new Meals();
            buttonMealsMenu.Show();
            this.Close();
        }

        private void ButtonOrdered(object sender, RoutedEventArgs e)
        {
            Ordered buttonOrdered = new Ordered();
            buttonOrdered.Show();
            this.Close();
        }

        
    }
}
